Chris Pollett > Old Classes >
CS152

( Print View )

Student Corner:
  [Grades Sec1]

  [Submit Sec1]

  [Class Sign Up Sec1]

  [
Lecture Notes]
  [Discussion Board]

Course Info:
  [Texts & Links]
  [Topics/Outcomes]
  [Outcomes Matrix]
  [Grading]
  [HW/Quiz Info]
  [Exam Info]
  [Regrades]
  [Honesty]
  [Additional Policies]
  [Announcements]

HWs and Quizzes:
  [Hw1]  [Hw2]  [Hw3]
  [Hw4]  [Hw5]  [Quizzes]

Practice Exams:
  [Mid]  [Final]

                           












HW#3 --- last modified February 28 2019 22:25:36..

Solution set.

Due date: Apr 6

Files to be submitted:
  Hw3.zip

Purpose: To gain a first-hand knowledge of variable scoping by examining assembly code output. To learn about different approaches to the object-oriented programming language paradigm.

Related Course Outcomes:

The main course outcomes covered by this assignment are:

LO2 -- Have a basic knowledge of the procedural, object-oriented, functional, and logic programming paradigms.

LO4 -- Critique the design of a programming language

LO7 -- Understand variable scoping and lifetimes.

Specification:

For this homework I want you to code a text-based interface, so that two people can play the game Chomp. I actually want you to code this twice: once in C++, and once using Objective-C. The grader will unzip your project, switch into that directory, and type "make chompcplusplus" to build the C++ version and type "make chompobjectivec" to build the Objective-C version of your project. Both versions produce an executable named chomp. So the grader can then type "./chomp" to execute the given program. Your program should then print:

Please enter the length of the chocolate bar:

And allows the user to enter an positive integer chocolate bar length less than 20. After this has been done. The program should print:

Please enter the width of the chocolate bar:

And allows the user to enter an positive integer chocolate bar width less than 40. Then the program should using character graphics draw the game board, say it is Player A's turn, and ask for a move of Player A. For a 3x5 board, this might look like:

Player A's Turn

    1  2  3  4  5

 1  O  X  X  X  X 

 2  X  X  X  X  X 
 
 3  X  X  X  X  X

Please enter the row of the move for Player A:

After this is entered it asks for the column of the move for A. Your program should check if the move is legal. If not, it should get the user to enter the move again. If it is legal, the program should draw the resulting board. and prompt for a move for Player B. And so on. Note both player's are assumed to be humans, you are NOT writing an AI for this game. After each turn your programs should be checking, if someone has eaten the poisoned chocolate square and if so declare a winner. Your programs then may ask if the player's want to play another game.

For both implementations of chomp I want you to write at least three classes. I also want you to make use of both public and private variables, public and private member functions. You should have at least one class that inherits from some other class. Your programs should each make use of one language construct that is not available in the other language. As part of your make commands, I want you to compile each of your programs to assembly. Next I want you to look at the assembly for both your C++ and Objective-C programs and answer the following questions:

  1. How are method names mangled for each language in producing assembly?
  2. In terms of where functions are stored is there any difference between private/public functions?
  3. How are field variables stored? Can you discern their scope based on the assembled output?
  4. Try to describe in English what is happening when the assembly code for object construction is called?
  5. How is method overriding implemented in the assembly?
  6. Looking at the assembly output of each language, briefly discuss the pro's and con's of Objective C versus C++.

Put your answers in the file answers.txt. Make sure to list all group members at the start of the file. Include code snippets from your original code and assembly code which prove each of your answers. Answers without sufficient explanation will receive little credit.

Point Breakdown

Objective-C is a described (1/2 make as described; 1/2pt boards drawn correctly; 1/2pt only legal moves accepted; 1/2pt detects if someone wins game) 2pts
C++ is a described (1/2 make as described; 1/2pt boards drawn correctly; 1/2pt only legal moves accepted; 1/2pt detects if someone wins game) 2pts
answers.txt file as described. (1/2pt per question for the answer; 1/2 pt for relevant code snippets/answer) 6pts
Total10pts